package com.laoxiang.modules.system.controller;


import com.laoxiang.modules.system.entity.SysDept;
import com.laoxiang.modules.system.entity.vo.DeptTreeVO;
import com.laoxiang.modules.system.service.SysDeptService;
import com.laoxiang.utils.AppHttpCodeEnum;
import com.laoxiang.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


/**
 * 部门信息表(SysDept)表控制层
 *
 * @author db
 * @since 2023-09-03 22:33:40
 */
@RestController
@RequestMapping("/sysDept")
@Api(tags = "部门管理")
public class SysDeptController {
    /**
     * 服务对象
     */
    @Resource
    private SysDeptService sysDeptService;

    @ApiOperation(httpMethod = "GET",value = "获得部门列表")
    @GetMapping("/getDeptList")
    public ResponseResult getDeptList(SysDept sysDept){
        List<SysDept> deptList = sysDeptService.getDeptList(sysDept);
        return ResponseResult.okResult(deptList);
    }

    @ApiOperation(httpMethod = "GET",value = "获得部门树")
    @GetMapping("/getDeptTreeSelect")
    public ResponseResult getDeptTreeSelect(){
        List<DeptTreeVO> deptTreeSelect = sysDeptService.getDeptTreeSelect();
        return ResponseResult.okResult(deptTreeSelect);
    }

    @ApiOperation(httpMethod = "POST",value = "增加部门")
    @PostMapping("/addDept")
    public ResponseResult addDept(@RequestBody SysDept sysDept){
        int i = sysDeptService.addDept(sysDept);
        if(i>0){
            return ResponseResult.okResult();
        }else{
            return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
        }
    }

    @ApiOperation(httpMethod = "GET",value = "通过部门id获得部门信息")
    @GetMapping("/getSysDeptById/{deptId}")
    public ResponseResult getSysDeptById(@PathVariable("deptId") Long deptId){
        SysDept sysDept = sysDeptService.getSysDeptById(deptId);
        return ResponseResult.okResult(sysDept);
    }

    @ApiOperation(httpMethod = "PUT",value = "修改部门")
    @PutMapping("/updateDept")
    public ResponseResult updateDept(@RequestBody SysDept sysDept){
        sysDeptService.updateDept(sysDept);
        return ResponseResult.okResult();
    }

    @ApiOperation(httpMethod = "DELETE",value = "删除部门")
    @DeleteMapping("/deleteDeptById/{deptId}")
    public ResponseResult deleteDeptById(@PathVariable("deptId") Long deptId){
        sysDeptService.deleteDeptById(deptId);
        return ResponseResult.okResult();
    }
}

